/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.antlr; import antlr.*; /** * <b>SOFTWARE RIGHTS</b> * <p> * ANTLR 2.6.0 MageLang Institute * <p> * We reserve no legal rights to the ANTLR--it is fully in the * public domain. An individual or company may do whatever * they wish with source code distributed with ANTLR or the * code generated by ANTLR, including the incorporation of * ANTLR, or its output, into commerical software. * <p> * We encourage users to develop software with ANTLR. However, * we do ask that credit is given to us for developing * ANTLR. By "credit", we mean that if you use ANTLR or * incorporate any source code into one of your programs * (commercial product, research project, or otherwise) that * you acknowledge this fact somewhere in the documentation, * research report, etc... If you like ANTLR and have * developed a nice tool with the output, please mention that * you developed it using ANTLR. In addition, we ask that the * headers remain intact in our source code. As long as these * guidelines are kept, we expect to continue enhancing this * system and expect to make other tools available as they are * completed. * <p> * The ANTLR gang: * @version ANTLR 2.6.0 MageLang Institute * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a> * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a> */ import antlr.collections.impl.BitSet; class DefaultToolErrorHandler implements antlr.ToolErrorHandler { //CharFormatter javaCharFormatter = new JavaCharFormatter(); public DefaultToolErrorHandler() { } /** Dump token/character sets to System.out * @param lexicalAnalysis true for lexical rule * @param depth The depth of the ambiguity * @param sets An array of bitsets containing the ambiguities */ private void dumpSets(Grammar grammar, boolean lexicalAnalysis, int depth, Lookahead[] sets) { /* for (int i = 1; i <= depth; i++) { System.out.print("\tk==" + i + ":"); if (lexicalAnalysis) { String bits = sets[i].fset.toStringWithRanges(",", javaCharFormatter); if ( sets[i].containsEpsilon() ) { System.out.print("<end-of-token>"); if ( bits.length()>0 ) { System.out.print(","); } } System.out.println(bits); } else { System.out.println(sets[i].fset.toString(",", grammar.tokenManager.getVocabulary())); } } */ } /** Issue a warning about ambiguity between a alternates * @param blk The block being analyzed * @param lexicalAnalysis true for lexical rule * @param depth The depth of the ambiguity * @param sets An array of bitsets containing the ambiguities * @param altIdx1 The zero-based index of the first ambiguous alternative * @param altIdx2 The zero-based index of the second ambiguous alternative */ public void warnAltAmbiguity( Grammar grammar, AlternativeBlock blk, boolean lexicalAnalysis, int depth, Lookahead[] sets, int altIdx1, int altIdx2) { /* if ( blk instanceof RuleBlock && ((RuleBlock)blk).isLexerAutoGenRule() ) { System.out.print("warning: lexical nondeterminism between rules "); Alternative ai = blk.getAlternativeAt(altIdx1); Alternative aj = blk.getAlternativeAt(altIdx2); RuleRefElement rri = (RuleRefElement)ai.head; RuleRefElement rrj = (RuleRefElement)aj.head; String ri = CodeGenerator.reverseLexerRuleName(rri.targetRule); String rj = CodeGenerator.reverseLexerRuleName(rrj.targetRule); System.out.println(ri+" and "+rj+" upon"); dumpSets(grammar, lexicalAnalysis, depth, sets); return; } System.out.println( "warning: line " + blk.getLine() + ": " + (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon" ); dumpSets(grammar, lexicalAnalysis, depth, sets); System.out.println("\tbetween alts " + (altIdx1+1) + " and " + (altIdx2+1) + " of block"); */ } /** Issue a warning about ambiguity between an alternate and exit path. * @param blk The block being analyzed * @param lexicalAnalysis true for lexical rule * @param depth The depth of the ambiguity * @param sets An array of bitsets containing the ambiguities * @param altIdx The zero-based index of the ambiguous alternative */ public void warnAltExitAmbiguity( Grammar grammar, BlockWithImpliedExitPath blk, boolean lexicalAnalysis, int depth, Lookahead[] sets, int altIdx ) { System.out.println( "warning: line " + blk.getLine() + ": " + (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon" ); dumpSets(grammar, lexicalAnalysis, depth, sets); System.out.println("\tbetween alt " + (altIdx+1) + " and exit branch of block"); } }